package com.vpx.server.controller.system;

import com.vpx.server.bean.order.base.BaseDelOrder;
import com.vpx.server.bean.order.base.BaseIdStrOrder;
import com.vpx.server.bean.order.system.ProjectFlowOrder;
import com.vpx.server.bean.order.system.ProjectFlowPageOrder;
import com.vpx.server.bean.result.system.ProjectFlowPageResult;
import com.vpx.server.bean.result.system.ProjectFlowResult;
import com.vpx.server.framework.authority.AuthPoicy;
import com.vpx.server.framework.authority.RequestAuth;
import com.vpx.server.framework.base.ResultMsg;
import com.vpx.server.service.system.ProjectFlowService;
import com.vpx.server.service.system.SqlExtService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工程管理
 */
@RestController
@RequestMapping(value = "/api/projectFlow")
@Api(tags = "工程流程管理")
public class ProjectFlowController {

    @Autowired
    private ProjectFlowService projectFlowService;
    @Resource
    private SqlExtService sqlExtService;

    @PostMapping("/insertPorjectFlow")
    @ApiOperation("新增工程流程")
    //@RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg insert(@Validated @RequestBody ProjectFlowOrder order) {
        return projectFlowService.saveProjectFlow(order);
    }

    @DeleteMapping("/deleteProjectFlow")
    @ApiOperation("删除工程流程")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg deleteProjectFlow(@Validated @RequestBody BaseDelOrder order) {
        return projectFlowService.deleteProjectFlow(order);
    }

    @PostMapping("/updateProjectFlowName")
    @ApiOperation("修改工程流程名称")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg updateProjectFlowName(@RequestBody ProjectFlowOrder order) {
        this.sqlExtService.execute("update c_project_attr set name = '"+order.getFlowName()+"' where id = '"+order.getId()+"'");
        return ResultMsg.success();
    }
    @PostMapping("/updateProjectFlow")
    @ApiOperation("修改工程流程")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg updateById(@RequestBody ProjectFlowOrder order) {
        return projectFlowService.updateProjectFlowById(order);
    }

    @GetMapping("/selectProjectFlowById")
    @ApiOperation("查询工程流程")
    @RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg<ProjectFlowResult> selectById(BaseIdStrOrder order) {
        return projectFlowService.selectProjecFlowById(order);
    }

    @GetMapping("/pageQueryProjectFlow")
    @ApiOperation("分页查询工程")
    //@RequestAuth(poicy = AuthPoicy.AUTH)
    public ResultMsg<ProjectFlowPageResult> pageQueryProjectFlow(ProjectFlowPageOrder order) {

        return projectFlowService.pageQueryProjectFlow(order);
    }



}
